<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1100px" append-to-body>
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline>
                <el-form-item label="商品SKU" prop="seller_sku">
                    <el-input v-model.trim="queryParams.seller_sku" placeholder="请输入SKU" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="创建时间" prop="create_time">
                    <el-date-picker v-model="queryParams.create_time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="card">
            <el-table v-loading="loading" :data="tableData" border script>
                <el-table-column label="商品sku" prop="seller_sku" min-width="160" show-overflow-tooltip></el-table-column>
                <el-table-column label="图片" min-width="90">
                    <template slot-scope="scope">
                        <ImageUploadImg v-model="scope.row.image_url" :readOnly="true"></ImageUploadImg>
                    </template>
                </el-table-column>
                <el-table-column label="入库数量" prop="in_stores_quantity"></el-table-column>
                <!-- <el-table-column label="入库单价" prop="warehouse_price"></el-table-column> -->
                <el-table-column label="仓库分区" prop="warehouse_position"></el-table-column>
                <el-table-column label="货架位" prop="warehouse_partition">
                    <template slot-scope="scope">
                        {{ scope.row.warehouse_partition == 1 ? '拣货区' : '次品区' }}
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" prop="create_time" min-width="160"></el-table-column>
                
                <el-table-column label="操作" min-width="140" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-thumb" @click="selectRow(scope.row)">选择</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
        </div>
    </el-dialog>
</template>

<script>
import { getReStoresDetail } from '@/api/warehouse'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'DetailDialogspuinfo',
    components: {},
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            showSearch: true,
            // 查询参数
            queryParams: {
                seller_sku: undefined,
                create_time: []
            },
            loading: false,
            // 表格数据
            tableData: [],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            total: 0,
        }
    },
    computed: {
        title() {
            return `商品列表`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    watch: {
        params: {
            handler(val) {
                if (val) {
                    this.getList()
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {
        // this.getList()
    },
    methods: {
        selectRow(row) {
            this.$emit('selectRow', row)
            this.cancel()
        },
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },
        getList() {
            this.loading = true
            const qyparams = { ...this.pageInfo, ...this.queryParams, in_number: this.params.in_number }
            if (qyparams.create_time?.length == 2) {
                qyparams.create_time = [parseTime(qyparams.create_time[0], 'y-m-d'), parseTime(qyparams.create_time[1], 'y-m-d')]
            }
            getReStoresDetail(qyparams)
                .then(res => {
                    this.tableData = res.data.list
                    this.total = res.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },
        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },

        cancel() {
            this.dialogVisible = false
            this.$emit('cancel')
        },
    },
}
</script>

<style>
.form-class.el-form .el-form-item {
    width: 100%;
    margin-right: 0;
}
.form-class.el-form .el-form-item .el-input {
    width: 400px;
}
.header {
    padding-bottom: 8px;
    border-bottom: 1px solid #f5f5f5;
    margin-bottom: 16px;
}
.header .header-title {
    margin-left: 16px;
    font-size: 16px;
}
</style>
<style lang="scss" scoped>
/* 统计卡片 */
::v-deep .chart-card {
    color: #606266;
    margin: 10px 0;
    .el-card__header,
    .el-card__body {
        padding-left: 32px;
    }
}
.chart-card-num {
    font-size: 30px;
}

.chart-card-content {
    height: 30px;
    .content-title {
        font-weight: bold;
        font-size: 20px;
        color: #303133;
    }
}
</style>
